package com.nanoso.handler;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nanoso.service.content.ContentService;

public class UrlMessageListener implements MessageListener {
	Log log = LogFactory.getLog(UrlMessageListener.class);
	private ContentService contentService;

	public void setContentService(ContentService contentService) {
		this.contentService = contentService;
	}

	@Override
	public void onMessage(Message message) {
		TextMessage text = (TextMessage) message;
		if (null == text)
			return;

		Long id = null;
		try {
			id = text.getLongProperty("id");
		} catch (JMSException e) {
			log.error("get message error", e);
		}
		if (null == id)
			return;

		this.contentService.handleContent(id);
		log.info("Recive message success id:" + id);
	}

}
